<template>
  <div class="addressExhibition">
    <p class="address-info-title">已有地址</p>
    <div class="default">
      <p class="title">当前默认地址</p>
      <div class="area">
        <div class="area-icon">
          <i class="el-icon-location-outline"></i>
        </div>
        <div class="area-info">
          <p class="name">{{ defaultAddress.area_name }}</p>
          <p class="desc">{{ defaultAddress.desc }}</p>
        </div>
      </div>
    </div>
    <ul class="address">
      <li v-for="item in addressArray" :key="item.id">
        <p class="userInfo">
          <span class="userName">{{ item.name }}</span
          ><span class="userPhone">{{ item.phone }}</span>
          <button class="setDefault" @click="setDefaultAddress(item.id)">
            设置为默认地址
          </button>
        </p>
        <div class="area-con">
          <div class="area-info">
            <p class="area name">{{ item.area_name }}</p>
            <p class="area desc">{{ item.desc }}</p>
          </div>
          <div class="operate">
            <button class="" @click="delAddressSingle(item.id)">删除</button>
            <button class="" @click="">修改</button>
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import {
  delAddress,
  setDefault,
  getDefault,
  getAddress,
} from "../assets/request.js";
export default {
  name: "AddressExhibition",
  data() {
    return {
      // addressArray: [],
      defaultAddress: {},
      addressArray: [],
    };
  },
  // props: ["addressArray"],
  methods: {
    async delAddressSingle(id) {
      const resDelAddress = await delAddress({}, id);
      this.getAddressArray();
    },
    async getDefaultAddress() {
      const resGetDefault = await getDefault();
      this.defaultAddress = resGetDefault.data.result;
    },
    async setDefaultAddress(id) {
      const resSetDefault = await setDefault({}, id);
      this.getDefaultAddress();
    },
    async getAddressArray() {
      const resGetAddress = await getAddress();
      this.addressArray = resGetAddress.data.result;
    },
  },
  mounted() {
    this.getAddressArray();
    this.getDefaultAddress();
  },
};
</script>

<style lang="scss" scoped>
@import "../assets/style/cover2Btn.scss";
.addressExhibition {
  padding: 30px;
  .address-info-title {
    height: 40px;
    padding-left: 20px;
    margin-bottom: 30px;
    background-color: #2f333a;
    line-height: 40px;
    color: white;
    font-size: 16px;
  }
  .default {
    width: 500px;
    height: 50px;
    margin-bottom: 50px;
    box-shadow: 0 5px 10px lightgray;
    .title {
      width: 480px;
      height: 30px;
      padding-left: 20px;
      background-color: #2f333a;
      line-height: 30px;
      font-size: 16px;
      color: white;
    }
    .area {
      display: flex;
      width: 100%;
      height: 50px;
      background-color: white;
      box-shadow: 0 5px 10px lightgray;
      .area-icon {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 50px;
        height: 50px;
        i {
          width: 30px;
          height: 30px;
          font-size: 30px;
        }
      }
      .area-info {
        display: flex;
        flex-direction: column;
        justify-content: center;
        height: 50px;
      }
    }
  }
  .address {
    li {
      width: 500px;
      height: 100px;
      margin-bottom: 20px;
      box-shadow: 0 5px 10px lightgray;
      .userInfo {
        position: relative;
        width: 500px;
        height: 30px;
        background-color: #2f333a;
        line-height: 35px;
        color: white;
        .userName {
          margin: 0 20px;
          font-size: 20px;
        }
        .setDefault {
          position: absolute;
          right: 30px;
          top: 50%;
          transform: translate(0, -50%);
          padding: 2px 5px;
          border: none;
        }
      }
      .area-con {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 500px;
        height: 70px;
        .area-info {
          width: 350px;
          font-size: 12px;
          .area {
            padding-top: 4px;
            margin-left: 20px;
          }
        }
        .operate {
          width: 150px;
          margin-right: 10px;
          button {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 100px;
            height: 30px;
            margin: 0 10px;
            // border: 1px solid rgb(20, 20, 20);
          }
        }
      }
    }
  }
}
</style>
